<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增辅料异常记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-exception-add">
            <div class="form-group" th:object="${ingredients}">
                <label class="col-sm-3 control-label is-required">异常辅料：</label>
                <div class="col-sm-8">
                    <select  class="form-control" data-none-selected-text="请选择" onchange="getSub(this.value)">
                        <option value="">请选择</option>
                        <option th:each="ing : ${ingredients}" th:text="${ing.name}" th:value="${ing.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">子名称：</label>
                <div class="col-sm-8">
                   <input name="partId"  id="ppp"   type="hidden"> 
                   <select id="subIdss" class="form-control"  onchange="getSubN(this.value)">
                        <option value="">请选择</option>

                    </select>
                </div>
            </div>
            <!--<div class="form-group">    -->
                <!--<label class="col-sm-3 control-label is-required">辅料表id：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<input name="partId" class="form-control" type="text" required>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">异常数量：</label>
                <div class="col-sm-8">
                    <input name="changeValue" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group" th:object="${users}">
                <label class="col-sm-3 control-label">发现者：</label>
                <div class="col-sm-8">
                    <select name="discoverer" class="form-control" data-none-selected-text="请选择">
                        <option value="">请选择</option>
                        <option th:each="user : ${users}" th:text="${user.userName}" th:value="${user.userName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发现时间：</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control time-input" id="startTime" placeholder="发现时间"
                           name="findDate" data-format="yyyy-MM-dd"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/exception"
        $("#form-exception-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-exception-add').serialize());
            }
        }
        
        //子东西改变的时候
        function getSubN(value) {
        	$("#ppp").val(value);
        	
        }
        function getSub(value) {
          /*   var arrays = [[${ingredients}]];
            for (var i = 0; i < arrays.length; i++) {
                if(value == arrays[i].id){
                    $("#subName").val(arrays[i].subName);
                }
            } */
            var s =" <option value=''>请选择</option>"
            if(value == ""){
            	$("#subIdss").html(s);
				return;      
            }
            $.ajax({
	            type: "POST",
	            url: prefix + "/selectSubName?partId="+value,
	            success: function(result) {
	            		console.log(result)
	                if (result.code == web_status.SUCCESS) {
	                	
	                　　　	　for (var i = 0; i < result.data.length; i++) {
							s=s+"<option value='"+result.data[i].id+"'>"+result.data[i].subName+"</option>";
	                　　　　		//如果在select中传递其他参数，可以在option 的value属性中添加参数
	                　　　	　	//	$("#subId").append("<option value="+result.data[i].id+">"+result.data[i].subName+"</option>");
	                	　　}
	                	
	                　　　	$("#subIdss").html(s);
	                } else {
						$.modal.alertError(result.msg);
					}
	            },
	            error: function(error) {
	                $.modal.alertWarning("查询失败。");
	            }
	        });
            
            
        }
    </script>
</body>
</html>